package org.happen.android.ui;

import org.happen.android.R;
import org.happen.android.bean.BaseRequest;
import org.happen.android.bean.request.exts.CommentReq;
import org.happen.android.bean.request.exts.MainReq;
import org.happen.android.bean.request.exts.SendMessageReq;
import org.happen.android.bean.response.JsonStrResponse;
import org.happen.android.core.net.AppRequestManager;
import org.happen.android.core.net.OnRequestCallback;
import org.happen.android.core.net.OnRequestCallback2;
import org.liushui.mycommons.android.annotation.OnClick;
import org.liushui.mycommons.android.annotation.ViewInject;
import org.liushui.mycommons.android.annotation.helper.InjectHelper;
import org.liushui.mycommons.android.log.McLog;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

/**
 * Created by lenovo on 2014/4/19.
 */
public class TestActivity extends Activity
{
	AppRequestManager requestControl;

	@ViewInject(R.id.button)
	Button button1;

	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.act_test);
		requestControl = AppRequestManager.getInstance();

		InjectHelper.init(this, this);
	}

	@OnClick({ R.id.button, R.id.button1, R.id.button2 })
	View.OnClickListener test1ClickListener = new View.OnClickListener() {
		public void onClick(View v)
		{
			switch (v.getId())
			{
				case R.id.button:
					MainReq mainReq = new MainReq();
					doRequest(mainReq);
					break;
				case R.id.button1:
					SendMessageReq sendMessageReq = new SendMessageReq();
					sendMessageReq.messageContent = "messageContent";
					sendMessageReq.messageLongitude = "messageLongitude";
					sendMessageReq.messageLatitude = "messageLatitude";
					sendMessageReq.messageAddress = "messageAddress";
					// sendMessageReq.image = "image";
					
					doRequest(sendMessageReq);
					break;
				case R.id.button2:
					CommentReq commentReq = new CommentReq();
					commentReq.flag = CommentReq.FLAG_UP;
					commentReq.messageId = 21;
					commentReq.commentContent = "test";
					doRequest(commentReq);
					break;
			}
		}
	};

	void doRequest(BaseRequest request)
	{
		requestControl.doGet(request, requestCallback);
	}

	OnRequestCallback requestCallback = new OnRequestCallback2() {
		public void onJsonResponse(BaseRequest request, JsonStrResponse jsonResponse)
		{
			McLog.i("request = " + request);
			McLog.i("jsonResponse = " + jsonResponse);
		}
	};
}